package mango.web.client.admin;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import mango.web.client.C;
import mango.web.client.View;

import com.google.gwt.dom.client.Style.BorderStyle;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;

public class AdminSearchView extends View {
	protected static AdminSearchView adminSearchView;

	public static AdminSearchView get(String key) {
		if ("".equals(key)) {
			if (AdminSearchView.adminSearchView == null) AdminSearchView.adminSearchView = new AdminSearchView().init();
			return AdminSearchView.adminSearchView;
		}
		return null;
	}

	public HTML searchHTML;
	public HTML appendedSearchHTML;

	public TextBox memberId;
	public TextBox contactId;
	public TextBox businessName;
	public TextBox abn;
	public HashMap<String, CheckBox> businessType = new HashMap<String, CheckBox>();
	public TextBox other;
	public HashMap<String, RadioButton> membershipType = new HashMap<String, RadioButton>();
	public HashMap<String, RadioButton> financialMember = new HashMap<String, RadioButton>();
	public HashMap<String, RadioButton> annualReport = new HashMap<String, RadioButton>();
	//public TextBox authorisedContact;
	public HashMap<String, RadioButton> marketingGroupUsed = new HashMap<String, RadioButton>();
	public HashMap<String, RadioButton> packsOwnProduce = new HashMap<String, RadioButton>();
	public TextBox marketGroup;
	public TextArea brand;

	public HTML contactHTML;
	public FlexTable tableContact;
	public TextBox firstname;
	public TextBox surname;
	public TextBox BHPhone;
	public TextBox AHPhone;
	public TextBox fax;
	public TextBox identifier;
	public TextBox mobile;
	public TextBox email;
	public HashMap<String, CheckBox> service = new HashMap<String, CheckBox>();

	public TextArea businessStreet;
	public TextBox businessCity;
	public TextBox businessState;
	public TextBox businessCountry;
	public TextBox businessPostCode;
	public TextArea postalStreet;
	public TextBox postalCity;
	public TextBox postalState;
	public TextBox postalCountry;
	public TextBox postalPostCode;

	public TextArea physicalLocation;
	public TextBox postCode;
	public TextBox state;

	public TextBox yearPlanting;
	public ListBox varietyId;
	public TextBox tree;
	public TextBox treeTotal;

	public HashMap<String, RadioButton> status = new HashMap<String, RadioButton>();
	//public CheckBox appendedBox;

	//public HTML currentHtml;
	//public TextBox currentTextBox;
	//public int current = 1110;
	//public List<String> memberIdList;

	//public Map<String, String> varietyMap;

	public Boolean preAppended = false;

	public AdminSearchView init() {

		this.panel.setSize("1000px", "570px");

		AbsolutePanel panel;
		Label label;
		HTML html;
		TextBox textBox;
		CheckBox checkBox;
		ListBox listBox;
		RadioButton radioButton;
		TextArea textArea;
		Button button;
		int top;
		int left;

		panel = new AbsolutePanel();
		panel.setSize("1000px", "100px");
		this.panel.add(panel, 0, 0);

		left = 967;

		html = new HTML("<img src='image/exit.png' style='cursor:pointer' title='exit'/>");
		panel.add(html, left, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				dialogBox.hide();
			}
		});

		html = new HTML("<img src='image/search.png' style='cursor:pointer' title='default search'/>");
		panel.add(html, left - 40, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				viewSearch("");
			}
		});
		this.searchHTML = html;
		
		//checkBox = new CheckBox("appended");
		//panel.add(checkBox, left - 320, 0);
		//this.appendedBox = checkBox;
		
		html = new HTML("<img src='image/search2.png' style='cursor:pointer' title='appended search'/>");
		panel.add(html, left - 270, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				viewSearch("appended");
			}
		});
		this.appendedSearchHTML = html;

		radioButton = new RadioButton("radStatus", "active");
		radioButton.setValue(true);
		panel.add(radioButton, left - 230, 0);
		this.status.put("active", radioButton);

		radioButton = new RadioButton("radStatus", "suspended");
		panel.add(radioButton, left - 170, 0);
		this.status.put("suspended", radioButton);

		radioButton = new RadioButton("radStatus", "all");
		panel.add(radioButton, left - 80, 0);
		this.status.put("all", radioButton);

		// TODO:htmlMember

		top = 30;
		label = this.newLabel("Members/Business Name", 150);
		panel.add(label, 34, top);

		textBox = this.newTextBox("", 490);
		panel.add(textBox, 190, top);
		this.businessName = textBox;

		label = new Label("ABN");
		panel.add(label, 694, top);

		textBox = newTextBox("", 148);
		panel.add(textBox, 727, top);
		this.abn = textBox;

		top = 55;

		label = this.newLabel("Allied Business Type", 150);
		panel.add(label, 34, top);

		checkBox = new CheckBox("Grower");
		panel.add(checkBox, 190, top);
		this.businessType.put("Grower".toUpperCase(), checkBox);

		checkBox = new CheckBox("Packaging");
		panel.add(checkBox, 285, top);
		this.businessType.put("Packaging".toUpperCase(), checkBox);

		checkBox = new CheckBox("Export");
		panel.add(checkBox, 385, top);
		this.businessType.put("Export".toUpperCase(), checkBox);

		checkBox = new CheckBox("Consultant");
		panel.add(checkBox, 528, top);
		this.businessType.put("Consultant".toUpperCase(), checkBox);

		checkBox = new CheckBox("Wholesaler");
		panel.add(checkBox, 636, top);
		this.businessType.put("Wholesaler".toUpperCase(), checkBox);

		checkBox = new CheckBox("Goverment Agency");
		panel.add(checkBox, 738, top);
		this.businessType.put("Goverment Agency".toUpperCase(), checkBox);

		top = 70;

		checkBox = new CheckBox("Processor");
		panel.add(checkBox, 190, top);
		this.businessType.put("Processor".toUpperCase(), checkBox);

		checkBox = new CheckBox("Retailer");
		panel.add(checkBox, 285, top);
		this.businessType.put("Retailer".toUpperCase(), checkBox);

		checkBox = new CheckBox("Research/Extension");
		panel.add(checkBox, 385, top);
		this.businessType.put("Research/Extension".toUpperCase(), checkBox);

		checkBox = new CheckBox("Transport");
		panel.add(checkBox, 528, top);
		this.businessType.put("Transport".toUpperCase(), checkBox);

		checkBox = new CheckBox("Other");
		panel.add(checkBox, 636, top);
		this.businessType.put("Other".toUpperCase(), checkBox);

		textBox = newTextBox("", 172);
		panel.add(textBox, 695, top);
		this.other = textBox;

		label = this.newLabel("Member ID", 72);
		panel.add(label, 918, 25);

		textBox = this.newTextBox("", 74);
		panel.add(textBox, 908, 40);
		this.memberId = textBox;

		label = this.newLabel("Contract ID", 74);
		panel.add(label, 918, 60);

		textBox = newTextBox("", 74);
		panel.add(textBox, 908, 75);
		this.contactId = textBox;

		// TODO:htmlMemberDetail
		AbsolutePanel panel2 = new AbsolutePanel();
		panel2.setSize("443px", "143px");

		html = new HTML("<b style='color:red'>AMIA Member Details</b>");
		panel2.add(html, 10, 0);

		this.panel.add(panel2, 10, 90);

		panel = new AbsolutePanel();
		panel.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
		panel.getElement().getStyle().setBorderWidth(2, Unit.PX);
		panel2.add(panel, 0, 13);
		panel.setSize("439px", "90px");

		top = 5;
		label = this.newLabel("Membership Type", 150);
		panel.add(label, 10, top);

		radioButton = new RadioButton("rad1", "Producer");
		panel.add(radioButton, 166, top);
		this.membershipType.put("Producer".toUpperCase(), radioButton);

		radioButton = new RadioButton("rad1", "Allied");
		panel.add(radioButton, 253, top);
		this.membershipType.put("Allied".toUpperCase(), radioButton);

		top = 25;

		label = this.newLabel("Financial Member", 150);
		panel.add(label, 10, top);

		radioButton = new RadioButton("rad2", "Yes");
		panel.add(radioButton, 166, top);
		this.financialMember.put("Yes".toUpperCase(), radioButton);

		radioButton = new RadioButton("rad2", "No");
		panel.add(radioButton, 225, top);
		this.financialMember.put("No".toUpperCase(), radioButton);

		top = 45;

		label = this.newLabel("Send annual report by", 150);
		panel.add(label, 10, top);

		radioButton = new RadioButton("rad3", "Mail");
		panel.add(radioButton, 166, top);
		this.annualReport.put("Mail".toUpperCase(), radioButton);

		radioButton = new RadioButton("rad3", "Email");
		panel.add(radioButton, 225, top);
		this.annualReport.put("Email".toUpperCase(), radioButton);

		top = 65;

		//label = this.newLabel("Authorised Contract", 150);
		//panel.add(label, 10, top);

		//textBox = this.newTextBox("", 255);
		//panel.add(textBox, 166, top);
		//this.authorisedContact = textBox;

		// TODO:htmlGrower
		panel2 = new AbsolutePanel();
		panel2.setSize("536px", "143px");

		html = new HTML("<b style='color:red'>Grower Packing Practices</b>");
		panel2.add(html, 10, 0);

		this.panel.add(panel2, 464, 90);

		panel = new AbsolutePanel();
		panel.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
		panel.getElement().getStyle().setBorderWidth(2, Unit.PX);
		panel2.add(panel, 0, 14);
		panel.setSize("532px", "90px");

		top = 5;

		label = this.newLabel("Marketing Group Used", 150);
		panel.add(label, 10, top);

		radioButton = new RadioButton("rad4", "Yes");
		panel.add(radioButton, 166, top);
		this.marketingGroupUsed.put("Yes".toUpperCase(), radioButton);

		radioButton = new RadioButton("rad4", "No");
		panel.add(radioButton, 213, top);
		this.marketingGroupUsed.put("No".toUpperCase(), radioButton);

		label = this.newLabel("Packs own produce", 150);
		panel.add(label, 260, top);

		radioButton = new RadioButton("rad5", "Yes");
		panel.add(radioButton, 421, top);
		this.packsOwnProduce.put("Yes".toUpperCase(), radioButton);

		radioButton = new RadioButton("rad5", "No");
		panel.add(radioButton, 473, top);
		this.packsOwnProduce.put("No".toUpperCase(), radioButton);

		top = 25;

		label = this.newLabel("Market Group", 150);
		panel.add(label, 10, top);

		textBox = this.newTextBox("", 350);
		panel.add(textBox, 166, top);
		this.marketGroup = textBox;

		top = 45;

		label = this.newLabel("Brand", 150);
		panel.add(label, 10, top);

		textArea = new TextArea();
		panel.add(textArea, 166, top + 3);
		textArea.setSize("350px", "32px");
		this.brand = textArea;

		// TODO:htmlContact
		panel2 = new AbsolutePanel();
		panel2.setSize("990px", "443px");

		html = new HTML("<b style='color:red'>Contacts</b>");
		panel2.add(html, 10, 0);

		this.panel.add(panel2, 10, 200);

		panel = new AbsolutePanel();
		panel.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
		panel.getElement().getStyle().setBorderWidth(2, Unit.PX);
		panel2.add(panel, 0, 13);
		panel.setSize("986px", "180px");

		top = 5;
		left = 0;
		label = this.newLabel("First name", 70);
		panel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		panel.add(textBox, left + 80, top);
		this.firstname = textBox;

		left = 200;
		label = this.newLabel("Surname", 70);
		panel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		panel.add(textBox, left + 80, top);
		this.surname = textBox;

		top = 27;
		left = 0;
		label = this.newLabel("BH Phone", 70);
		panel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		panel.add(textBox, left + 80, top);
		this.BHPhone = textBox;

		left = 200;
		label = this.newLabel("AH Phone", 70);
		panel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		panel.add(textBox, left + 80, top);
		this.AHPhone = textBox;

		top = 49;
		left = 0;
		label = this.newLabel("Fax", 70);
		panel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		panel.add(textBox, left + 80, top);
		this.fax = textBox;

		left = 200;
		label = this.newLabel("Identifier", 70);
		panel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		panel.add(textBox, left + 80, top);
		this.identifier = textBox;

		top = 71;
		left = 0;
		label = this.newLabel("Mobile", 70);
		panel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		panel.add(textBox, left + 80, top);
		this.mobile = textBox;

		top = 93;
		left = 0;
		label = this.newLabel("Email", 70);
		panel.add(label, left, top);

		textBox = this.newTextBox("", 320);
		panel.add(textBox, left + 80, top);
		this.email = textBox;

		top = 125;
		left = 20;
		checkBox = new CheckBox("AMIA Activities FAX");
		panel.add(checkBox, left, top);
		this.service.put("AMIA Activities FAX".toUpperCase(), checkBox);

		checkBox = new CheckBox("SMS for Workshops");
		panel.add(checkBox, left + 200, top);
		this.service.put("SMS for Workshops".toUpperCase(), checkBox);

		top = 140;
		checkBox = new CheckBox("AMIA Activities EMAIL");
		panel.add(checkBox, left, top);
		this.service.put("AMIA Activities EMAIL".toUpperCase(), checkBox);

		checkBox = new CheckBox("EMAIL for Workshops");
		panel.add(checkBox, left + 200, top);
		this.service.put("EMAIL for Workshops".toUpperCase(), checkBox);

		top = 155;
		checkBox = new CheckBox("Mango Matters");
		panel.add(checkBox, left, top);
		this.service.put("Mango Matters".toUpperCase(), checkBox);

		checkBox = new CheckBox("FAX for Workshops");
		panel.add(checkBox, left + 200, top);
		this.service.put("FAX for Workshops".toUpperCase(), checkBox);

		// TODO:htmlContactAddress
		top = 5;
		left = 400;
		label = this.newLabel("Business Address", 70);
		panel.add(label, left, top);

		textArea = new TextArea();
		textArea.setSize("200px", "34px");
		panel.add(textArea, left + 80, top);
		this.businessStreet = textArea;

		top = 49;
		left = 400;
		label = this.newLabel("City/Town", 70);
		panel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		panel.add(textBox, left + 80, top);
		this.businessCity = textBox;

		top = 71;
		left = 400;
		label = this.newLabel("State", 70);
		panel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		panel.add(textBox, left + 80, top);
		this.businessState = textBox;

		top = 93;
		left = 400;
		label = this.newLabel("Country", 70);
		panel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		panel.add(textBox, left + 80, top);
		this.businessCountry = textBox;

		top = 115;
		left = 400;
		label = this.newLabel("* Post Code", 70);
		panel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		panel.add(textBox, left + 80, top);
		this.businessPostCode = textBox;

		// TODO:htmlContactPostal

		top = 5;
		left = 690;
		label = this.newLabel("Postal Address", 70);
		panel.add(label, left, top);

		textArea = new TextArea();
		textArea.setSize("200px", "34px");
		panel.add(textArea, left + 80, top);
		this.postalStreet = textArea;

		top = 49;
		left = 690;
		label = this.newLabel("City/Town", 70);
		panel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		panel.add(textBox, left + 80, top);
		this.postalCity = textBox;

		top = 71;
		left = 690;
		label = this.newLabel("State", 70);
		panel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		panel.add(textBox, left + 80, top);
		this.postalState = textBox;

		top = 93;
		left = 690;
		label = this.newLabel("Country", 70);
		panel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		panel.add(textBox, left + 80, top);
		this.postalCountry = textBox;

		top = 115;
		left = 690;
		label = this.newLabel("* Post Code", 70);
		panel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		panel.add(textBox, left + 80, top);
		this.postalPostCode = textBox;

		// TODO:htmlOrchard
		panel2 = new AbsolutePanel();
		panel2.setSize("990px", "443px");

		html = new HTML("<b style='color:red'>Orchards</b>");
		panel2.add(html, 10, 0);

		this.panel.add(panel2, 10, 400);

		panel = new AbsolutePanel();
		panel.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
		panel.getElement().getStyle().setBorderWidth(2, Unit.PX);
		panel2.add(panel, 0, 13);
		panel.setSize("986px", "90px");

		// TODO:htmlOrchardLocation
		top = 5;
		left = 20;
		label = this.newLabel("Physical Address of Orchard", 70);
		panel.add(label, left, top);

		textArea = new TextArea();
		textArea.setSize("300px", "32px");
		panel.add(textArea, left + 80, top);
		this.physicalLocation = textArea;

		top = 50;
		label = this.newLabel("* Post Code", 70);
		panel.add(label, left, top);

		textBox = this.newTextBox("", 70);
		panel.add(textBox, left + 80, top);
		this.postCode = textBox;

		label = this.newLabel("State", 70);
		panel.add(label, left + 140, top);

		textBox = this.newTextBox("", 70);
		panel.add(textBox, left + 220, top);
		this.state = textBox;

		// TODO:htmlOrchardVeriety
		top = 5;
		left = 420;
		label = this.newLabel("* Planted", 70);
		panel.add(label, left, top);

		textBox = this.newTextBox("", 70);
		panel.add(textBox, left + 80, top);
		this.yearPlanting = textBox;

		label = this.newLabel("Variety", 70);
		panel.add(label, left + 140, top);

		listBox = new ListBox();
		listBox.setWidth("180px");
		panel.add(listBox, left + 140 + 80, top);
		this.varietyId = listBox;

		label = this.newLabel("* Variety Tree Total", 70);
		panel.add(label, left + 400, top);

		textBox = this.newTextBox("", 70);
		panel.add(textBox, left + 400 + 80, top);
		this.tree = textBox;

		top = 50;
		label = this.newLabel("* Total Trees", 70);
		panel.add(label, left, top);

		textBox = this.newTextBox("", 70);
		panel.add(textBox, left + 80, top);
		this.treeTotal = textBox;
		
		html = new HTML("<b><pre>(*) :  x  =x  &lt;x  &lt;=x  &gt;x  &gt;=x  x..y </pre></b>");
		panel2.add(html, 10, 110);
		
		html = new HTML("<b><pre>(all text field) :  _ is not empty text</pre></b>");
		panel2.add(html, 10, 130);
		
		// TODO:AdminSearchView
		this.dialogBox = new DialogBox();
		this.dialogBox.setHTML("<b style='color:red'>Search for a Contact</b>");
		this.dialogBox.setModal(false);
		this.dialogBox.setWidget(this.panel);

		return this;
	}

	public AdminSearchView view() {
		Map<String, String> varietyMap = C.getVarietyMap();

		this.varietyId.addItem("", "");
		for (String key : varietyMap.keySet()) {
			this.varietyId.addItem(varietyMap.get(key), key);
		}

		return this;
	}

	public DialogBox dialogBox;

	public AdminSearchView viewSearch(String type) {
		this.adminSearchVo = this.getAdminSearchVo(type);
		this.dialogBox.hide();
		return this;
	}

	public AdminSearchVo adminSearchVo = new AdminSearchVo();

	public AdminSearchVo getAdminSearchVo(String type) {
		AdminView adminView = new AdminView();

		this.adminSearchVo = new AdminSearchVo();
		this.adminSearchVo.memberId = this.memberId.getText();
		this.adminSearchVo.businessName = this.businessName.getText();
		this.adminSearchVo.abn = this.abn.getText();
		this.adminSearchVo.businessType = adminView.getCheckBoxString(this.businessType);
		this.adminSearchVo.other = this.other.getText();
		this.adminSearchVo.membershipType = adminView.getRadioButtonString(this.membershipType);
		this.adminSearchVo.financialMember = adminView.getRadioButtonString(this.financialMember);
		this.adminSearchVo.annualReport = adminView.getRadioButtonString(this.annualReport);
		//this.adminSearchVo.authorisedContact = this.authorisedContact.getText();
		this.adminSearchVo.marketingGroupUsed = adminView.getRadioButtonString(this.marketingGroupUsed);
		this.adminSearchVo.packsOwnProduce = adminView.getRadioButtonString(this.packsOwnProduce);
		this.adminSearchVo.marketGroup = this.marketGroup.getText();
		this.adminSearchVo.brand = this.brand.getText();

		this.adminSearchVo.contactId = this.contactId.getText();
		this.adminSearchVo.firstname = this.firstname.getText();
		this.adminSearchVo.surname = this.surname.getText();
		this.adminSearchVo.BHPhone = this.BHPhone.getText();
		this.adminSearchVo.AHPhone = this.AHPhone.getText();
		this.adminSearchVo.fax = this.fax.getText();
		this.adminSearchVo.identifier = this.identifier.getText();
		this.adminSearchVo.mobile = this.mobile.getText();
		this.adminSearchVo.email = this.email.getText();
		this.adminSearchVo.service = adminView.getCheckBoxString(this.service);
		this.adminSearchVo.businessStreet = this.businessStreet.getText();
		this.adminSearchVo.businessCity = this.businessCity.getText();
		this.adminSearchVo.businessState = this.businessState.getText();
		this.adminSearchVo.businessCountry = this.businessCountry.getText();
		this.adminSearchVo.businessPostCode = this.businessPostCode.getText();
		this.adminSearchVo.postalStreet = this.postalStreet.getText();
		this.adminSearchVo.postalCity = this.postalCity.getText();
		this.adminSearchVo.postalState = this.postalState.getText();
		this.adminSearchVo.postalCountry = this.postalCountry.getText();
		this.adminSearchVo.postalPostCode = this.postalPostCode.getText();

		// this.adminSearchVo.orchardId;
		this.adminSearchVo.physicalLocation = this.physicalLocation.getText();
		this.adminSearchVo.postCode = this.postCode.getText();
		this.adminSearchVo.state = this.state.getText();

		// public Integer treeId;
		this.adminSearchVo.yearPlanting = this.yearPlanting.getText();
		this.adminSearchVo.varietyId = this.varietyId.getValue(this.varietyId.getSelectedIndex());
		// public String DTR;
		// public String BTR;
		// public String area;
		// public String areaType;
		this.adminSearchVo.tree = this.tree.getText();
		// add
		this.adminSearchVo.treeTotal = this.treeTotal.getText();

		this.adminSearchVo.status = adminView.getRadioButtonString(this.status);

		//this.adminSearchVo.appended = this.appendedBox.getValue();
		//if (this.preAppended) {
		//	this.adminSearchVo.memberIdList = AdminView.get("").memberIdList;
		//	this.adminSearchVo.contactIdList = C._contactIdList;
		//} else {
		//	this.adminSearchVo.memberIdList = new ArrayList<String>();
		//	this.adminSearchVo.contactIdList = new ArrayList<String>();
		//}
		
		if("appended".equals(type)){
			this.adminSearchVo.memberIdList = AdminView.get("").memberIdList;
			this.adminSearchVo.contactIdList = C._contactIdList;
			this.adminSearchVo.appended = true;
		} if("".equals(type)) {
			this.adminSearchVo.memberIdList = new ArrayList<String>();
			this.adminSearchVo.contactIdList = new ArrayList<String>();
			this.adminSearchVo.appended = false;
		}

		return this.adminSearchVo;
	}

	public AdminSearchVo setAdminSearchVo() {
		this.memberId.setText(this.adminSearchVo.memberId);
		this.businessName.setText(this.adminSearchVo.businessName);
		this.abn.setText(this.adminSearchVo.abn);
		// this.adminSearchVo.businessType = this.getCheckBoxString(this.businessType);
		//this.businessType.clear();
		for (String key : this.businessType.keySet()) {
			this.businessType.get(key).setValue(false);
		}
		this.other.setText(this.adminSearchVo.other);
		//this.adminSearchVo.membershipType = this.getRadioButtonString(this.membershipType);
		//this.membershipType.clear();
		for (String key : this.membershipType.keySet()) {
			this.membershipType.get(key).setValue(false);
		}
		//this.adminSearchVo.financialMember = this.getRadioButtonString(this.financialMember);
		//this.financialMember.clear();
		for (String key : this.financialMember.keySet()) {
			this.financialMember.get(key).setValue(false);
		}
		//this.adminSearchVo.annualReport = this.getRadioButtonString(this.annualReport);
		//this.annualReport.clear();
		for (String key : this.annualReport.keySet()) {
			this.annualReport.get(key).setValue(false);
		}
		//this.authorisedContact.setText(this.adminSearchVo.authorisedContact);
		//this.adminSearchVo.marketingGroupUsed = this.getRadioButtonString(this.marketingGroupUsed);
		//this.marketingGroupUsed.clear();
		for (String key : this.marketingGroupUsed.keySet()) {
			this.marketingGroupUsed.get(key).setValue(false);
		}
		//this.adminSearchVo.packsOwnProduce = this.getRadioButtonString(this.packsOwnProduce);
		//this.packsOwnProduce.clear();
		for (String key : this.packsOwnProduce.keySet()) {
			this.packsOwnProduce.get(key).setValue(false);
		}
		this.marketGroup.setText(this.adminSearchVo.marketGroup);
		this.brand.setText(this.adminSearchVo.brand);

		this.contactId.setText(this.adminSearchVo.contactId);
		this.firstname.setText(this.adminSearchVo.firstname);
		this.surname.setText(this.adminSearchVo.surname);
		this.BHPhone.setText(this.adminSearchVo.BHPhone);
		this.AHPhone.setText(this.adminSearchVo.AHPhone);
		this.fax.setText(this.adminSearchVo.fax);
		this.identifier.setText(this.adminSearchVo.identifier);
		this.mobile.setText(this.adminSearchVo.mobile);
		this.email.setText(this.adminSearchVo.email);
		//this.adminSearchVo.service = this.getCheckBoxString(this.service);
		//this.service.clear();
		for (String key : this.service.keySet()) {
			this.service.get(key).setValue(false);
		}
		this.businessStreet.setText(this.adminSearchVo.businessStreet);
		this.businessCity.setText(this.adminSearchVo.businessCity);
		this.businessState.setText(this.adminSearchVo.businessState);
		this.businessCountry.setText(this.adminSearchVo.businessCountry);
		this.businessPostCode.setText(this.adminSearchVo.businessPostCode);
		this.postalStreet.setText(this.adminSearchVo.postalStreet);
		this.postalCity.setText(this.adminSearchVo.postalCity);
		this.postalState.setText(this.adminSearchVo.postalState);
		this.postalCountry.setText(this.adminSearchVo.postalCountry);
		this.postalPostCode.setText(this.adminSearchVo.postalPostCode);

		// this.adminSearchVo.orchardId;
		this.physicalLocation.setText(this.adminSearchVo.physicalLocation);
		this.postCode.setText(this.adminSearchVo.postCode);
		this.state.setText(this.adminSearchVo.state);

		// public Integer treeId;
		this.yearPlanting.setText(this.adminSearchVo.yearPlanting);
		//this.adminSearchVo.varietyName = this.varietyName.getItemText(this.varietyName.getSelectedIndex());
		//this.varietyId.clear();
		Map<String, String> varietyMap = C.getVarietyMap();
		this.varietyId.clear();
		this.varietyId.addItem("", "");
		for (String key : varietyMap.keySet()) {
			this.varietyId.addItem(varietyMap.get(key), key);
		}
		for (int i = 0; i < this.varietyId.getItemCount(); i++) {
			if ((this.adminSearchVo.varietyId + "").equals(this.varietyId.getValue(i))) {
				this.varietyId.setSelectedIndex(i);
				break;
			}
		}
		this.varietyId.setSelectedIndex(0);
		// public String DTR;
		// public String BTR;
		// public String area;
		// public String areaType;
		this.tree.setText(this.adminSearchVo.tree);
		// add
		this.treeTotal.setText(this.adminSearchVo.treeTotal);
		//this.adminSearchVo.status = adminView.getRadioButtonString(this.status);

		//this.appendedBox.setValue(false);

		return this.adminSearchVo;
	}

	public void reset() {
		this.adminSearchVo = new AdminSearchVo();
		this.setAdminSearchVo();
	}
}
